<template>
  <div class="test-container">
    <div class="top-main">
      <search :listQuery="listQuery" :path="$route.name"></search>
    </div>
    <div class="bottom-main">
      <div class="list-button-group">
        <div class="button-item">
          <el-button type="primary" icon="el-icon-share" :disabled="selectrow.length > 0 ? false : true"
            @click="DialogOpenFenFa()">
            分发
          </el-button>
        </div>
        <!-- <div class="button-item">
          <el-button type="primary" :disabled="selectrow.length == 0" icon="el-icon-printer">
            打印
          </el-button>
        </div> -->
      </div>
      <div class="table-list">
        <el-table ref="tableSort" v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText"
          @selection-change="setSelectRows" highlight-current-row height="100%" :header-cell-style="{
            'border-bottom': '1px solid #cbcccd',
            'border-top': '1px solid #cbcccd',
          }">
          <el-table-column show-overflow-tooltip type="selection" width="55" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="序号" width="50">
            <template #default="scope">
              {{ scope.$index + listQuery.pageSize * (listQuery.pageIndex - 1) + 1 }}

            </template>
          </el-table-column>


          <el-table-column show-overflow-tooltip prop="pingzhengh" label="凭证号" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="状态" prop="zhuangtai" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.zhuangtai == 0">新单</span>
              <span v-if="scope.row.zhuangtai == 5">分发完成</span>
              <span v-if="scope.row.zhuangtai == 15">入库完成</span>
              <span v-if="scope.row.zhuangtai == 1">待审核</span>
              <span v-if="scope.row.zhuangtai == 2">审核驳回</span>
              <span v-if="scope.row.zhuangtai == 3">审核通过</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="物资区分" prop="wuziqfmc" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="物资分类" prop="wuzizymc" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="主管单位" prop="zhuguandwmc" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="发货单位" prop="fahuodw" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="经办人" prop="jingbanr" align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="创建时间" prop="create_time" width="180"
            align="center"></el-table-column>
          <el-table-column show-overflow-tooltip label="最后修改时间" prop="modify_time" width="180"
            align="center"></el-table-column>

          <!-- <el-table-column show-overflow-tooltip label="操作" width="100px" align="center">
            <template #default="{ row }">
              <el-button type="text" @click="fenfajg(row)">分发结果</el-button>
              <el-button type="text">配送信息</el-button>
            </template>
          </el-table-column> -->
        </el-table>
      </div>
      <el-pagination :background="background" :current-page="listQuery.pageIndex" :layout="layout"
        :page-size="listQuery.pageSize" :total="total" @current-change="handleCurrentChange"
        @size-change="handleSizeChange"></el-pagination>
    </div>


    <detail v-if="detailshow" :gobacktitle="gobacktitle" :datarow="detailrow"></detail>
    <!-- 导入文件start -->
    <el-dialog :close-on-click-modal="false" :visible.sync="importShow" destroy-on-close title="导入文件" class="m-dialog"
      :append-to-body="true">
      <upload api-url="xqzdDetail/import" @success="uploadSuccess" />
    </el-dialog>

    <!--分发 -->
    <fenfa ref="fenfa-dialog" @fetch-data="fetchData"></fenfa>


  </div>
</template>
<script>
let _listQuery = {
  zhuangtaiList: 2,
  pageIndex: 1,
  pageSize: 10,
  wuziqfid: "",
  zhuguandwid: "",
  zhuangtai: "",
}
import Upload from '@/components/Upload/upload'
import search from './components/search.vue'
import Fenfa from './components/page3Fenfa.vue'
import Detail from './components/page1Detail.vue'
import { queryPage, getOneDbd, queryFenfajgByPara } from '@/api/warehousing'

export default {
  name: 'Test',
  data() {
    return {
      listQuery: Object.assign({}, _listQuery),
      show: true,
      listLoading: false,
      total: 0,
      elementLoadingText: '正在加载...',
      list: [{ rkdh: 111, datalist: [{ bmm: 2222, wzmc: '物资名称1' }] }],
      layout: 'prev, pager, next, jumper',
      background: true,
      detailshow: false,
      importShow: false,
      gobacktitle: '',
      selectrow: [],
      detailrow: {},
      fenFaDialogVisible: false
    }
  },
  components: { Upload, search, Fenfa, Detail },
  created() {
    this.fetchData()
  },
  mounted() { },
  methods: {
    async DialogOpenFenFa() {
      if (this.selectrow.length !== 1) {
        this.$message({
          message: '请选择一条进行分发，不要多选',
          type: 'error',
        })
        return false
      }

      if (this.selectrow[0].zhuangtai != 3) {
        this.$message({
          message: '已经分发完成',
          type: 'error',
        })
        return false
      }


      const mxData = await getOneDbd({ id: this.selectrow[0].id })
      this.$refs['fenfa-dialog'].showEdit(mxData.data)
    },
    setSelectRows(val) {
      this.selectrow = val
    },
    async fetchData() {
      const RKDdata = await queryPage(this.listQuery)
      this.total = RKDdata.data.total
      this.list = RKDdata.data.rows
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.listQuery.pageIndex = val
      this.fetchData()
    },
    search() {//搜索
      this.listQuery.pageIndex = 1
      this.fetchData()
    },
    resetlist() {//重置
      this.listQuery = Object.assign({}, _listQuery)
      this.fetchData()
    },
    add() {
      this.addshow = true
      this.gobacktitle = '新增'
    },
    edit() {
      this.addshow = true
      this.gobacktitle = '编辑'
    },
    showdetail(row) {
      this.detailshow = true
      this.gobacktitle = '入库调拨单明细'
      this.detailrow = row
    },

    async fenfajg(row) {

      const RKDdata = await queryFenfajgByPara(row)


    },

    uploadSuccess() {
      this.importShow = false
    },
    uploadDB() {
      this.importShow = true
    },
  },
}
</script>
<style lang="scss" scoped>
.test-container {
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  background: #f6f8f9 !important;
  height: 100%;

  .top-main {
    width: 100%;
    background: #fff;
    padding: 10px 0;
  }

  .bottom-main {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    background-color: #fff;
    margin-top: 10px;
    padding-bottom: 10px;

    .list-button-group {
      display: flex;
      flex-direction: row;
      padding: 20px;

      .button-item {
        padding: 0px 10px;
      }

      .button-item:first-child,
      &:last-child {
        padding: 0px 10px 0 0;
      }
    }

    .table-list {
      flex: 1;
      padding: 0 20px 20px;
    }
  }

  .el-button {
    font-size: .14rem !important;
  }
}
</style>